<template>
	<view class="login">
		<view class="top_item">
			<text style="color: #000000;font-size: 22px;font-weight: bold;">密码登录</text>
		</view>
		<view class="input-item" style="margin-top: 80rpx;">
			<view class="title-content">
				<text class="title">账号:</text>
			</view>
			<input class="input" placeholder="手机号/邮箱"  @input="onEmail" style="margin-left: 40rpx;" />
		</view>
		<view class="input-item">
			<view class="title-content">
				<text class="title">密码:</text>
			</view>
			<input class="input" placeholder="请输入密码" @input="onPwd" style="margin-left: 40rpx;" />
		</view>
		<view class="button" @click="login">登录</view>
	</view>
</template>

<script>
	export default {
		data() {
			return {
				title: 'Hello',
				loginfrom: {
					username: "admin",
					password: "123456"
				}
			}
		},
		onLoad() {

		},
		methods: {
			onEmail:function(e) {
				this.username = e.detail.value
				console.log(e)
				console.log(e.detail.value)
			},
			onPwd:function(e) {
				this.password = e.target.value
				console.log(e.detail.value)
			},
			login() {
				uni.request({
					url: 'http://127.0.0.1:8888/api/private/v1/login',
					data: {
						username: this.username,
						password: this.password
					},
					method: "POST",
					success: res => {
						const {data:{data,meta}} = res;
						if(meta.status == 200){
							uni.showToast({
								title:'登录成功'
							});
							uni.navigateTo({
								url:'../TODoLIst/TODoLIst'
							})
							uni.setStorage({
								key: "token",
								data: data.token,
								success: (data) => {
									console.log("存储成功")
								},
								fail: () => {
									console.log("存储失败")
								}
							});
							
						}else{
							uni.showToast({
								title:"登录失败",
								icon:'error'
							})
						}
					}
				})
			},
		}
	}
</script>

<style>
	.top_item {
		display: flex;
		margin-top: 40rpx;
		margin-left: 32rpx;
		margin-right: 32rpx;
		justify-content: space-between;
	}

	.title-content {
		display: flex;
		justify-content: flex-start;
		align-items: center;
	}

	.title {
		font-size: 18px;
	}

	.input-item {
		display: flex;
		margin-left: 32rpx;
		margin-right: 32rpx;
		height: 50px;
		align-items: center;
		border-bottom: 1px solid #efeff4;
		margin-bottom: 20rpx;
	}

	.input {
		flex: 1;
	}

	.button {
		height: 50px;
		line-height: 50px;
		margin-top: 60rpx;
		margin-left: 32rpx;
		margin-right: 32rpx;
		border-radius: 50rpx;
		font-size: 20px;
		background-color: #008AFE;
		color: #FFFFFF;
		text-align: center;
	}
</style>
